var app = getApp()
var QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
Page({
  data: {
    objarr: [],
    position:[],
    width:0,
    imgheight:0,
    indexdata:{},
    catid:'',
    height:0,
    currentTab: 1663,
    page: 1,
    pagesize: 5,
    totalpage: 0,//最大页数
    nomore: true,
    study_is:'false',
    jiek:"news_list",
    isstudy:false
  },
  onShareAppMessage: function (res) {
    let member_id = app.globalData.userInfo.member_id
    return {
      title: '成纪先锋微平台',
      path: '/pages/index/index?inviter_id=' + member_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  onLoad: function (options) {
    var that = this;
    console.log(wx.getStorageSync('rd_session'))
    
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({
           width: res.windowWidth,
           height:res.windowHeight })
      }
    })

    app.ajax("index", {}, (data, err) => {
      this.setData({
        indexdata: data.data,
      })
      this.getData(this.data.currentTab,"news_list")
    })
  },
  getData(id,jk){
    let par
    if(jk == 'study'){
      this.setData({
        study_is:'true',
        jiek:jk
      })
      par = {
        page: this.data.page,
        page_size: this.data.page_size,
        types: id,
        rd_session: wx.getStorageSync("rd_session")
      }
    }else{
      this.setData({
        study_is: 'false',
        jiek:jk
      })
      par = {
        page: this.data.page,
        page_size: this.data.page_size,
        catid: id
      }
    }
    app.ajax(jk, par, (data, err) => {
      if(data.result == 'success'){
        this.setData({
          objarr: data.data.list,
          totalpage: data.data.total_page
        })
      }
      
    })
  },
  clicktab(e) {
    let tab = e.currentTarget.dataset.tab
    let jk = e.currentTarget.dataset.jk
    if (this.data.currentTab != tab) {
      this.setData({
        currentTab: tab,
        page: 1,
        nomore: true,
      })
      this.getData(tab,jk)
    }
  },
  //滑动到底部 上拉加载
  scrollBottom: function () {
    this.data.page++
    if (this.data.page > this.data.totalpage) {
      this.setData({
        nomore: false
      })
    } else {
      let params
      if (this.data.study_is == 'true'){
        params = {
          types: this.data.currentTab,
          page: this.data.page,
          page_size: this.data.pagesize,
          rd_session:wx.getStorageSync("rd_session")
        }
      }else{
        params = {
          catid: this.data.currentTab,
          page: this.data.page,
          page_size: this.data.pagesize
        }
      }
      app.ajax(this.data.jiek, params, (data, err) => {
        let arr = this.data.objarr;
        for (let item of data.data.list) {
          arr.push(item);
        }
        this.setData({
          objarr: arr
        })
      })
    }

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  tosearch(){
    wx.navigateTo({
      url: '/packageA/pages/search/search',
    })
  },
 
  imageLoad(e) {
    let that = this
    this.setData({
      imgheight: app.fixImgW(e, that.data.width),
    })
  },

 
  
});